From 9f5584f5b6e67627d6d721ed7003469263fdeaa9 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Fri, 9 Jan 2015 17:31:05 +0100 Subject: [PATCH] rwlock: allow arch to override read_unlock() atomic On x86, LOCK DEC is cheaper than LOCK CMPXCHG and doesn't require a retry loop around it. Signed-off-by: Jan Beulich Reviewed-by: Tim Deegan Reviewed-by: Andrew Cooper --- xen/common/spinlock.c | 16 ++++++++++------ xen/include/asm-x86/spinlock.h | 3 +++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 13340a3f61..f6925ec5f7 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -333,14 +333,18 @@ int _read_trylock(rwlock_t *lock) return 1; } -void _read_unlock(rwlock_t *lock) -{ - uint32_t x, y; +#ifndef _raw_read_unlock +# define _raw_read_unlock(l) do { \ + uint32_t x = (l)->lock, y; \ + while ( (y = cmpxchg(&(l)->lock, x, x - 1)) != x ) \ + x = y; \ +} while (0) +#endif +inline void _read_unlock(rwlock_t *lock) +{ preempt_enable(); - x = lock->lock; - while ( (y = cmpxchg(&lock->lock, x, x-1)) != x ) - x = y; + _raw_read_unlock(lock); } void _read_unlock_irq(rwlock_t *lock) diff --git a/xen/include/asm-x86/spinlock.h b/xen/include/asm-x86/spinlock.h index 06d9b048b2..757e20b861 100644 --- a/xen/include/asm-x86/spinlock.h +++ b/xen/include/asm-x86/spinlock.h @@ -31,4 +31,7 @@ static always_inline int _raw_spin_trylock(raw_spinlock_t *lock) return (oldval > 0); } +#define _raw_read_unlock(l) \ + asm volatile ( "lock; dec%z0 %0" : "+m" ((l)->lock) :: "memory" ) + #endif /* __ASM_SPINLOCK_H */ -- 2.30.2